package com.team2.insulatingtools.modular.tools.controller;

import cn.stylefeng.roses.kernel.office.api.OfficeExcelApi;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;

import com.alibaba.fastjson.JSONObject;
import com.team2.insulatingtools.modular.tools.entity.Tools;
import com.team2.insulatingtools.modular.tools.pojo.request.RecordStatisticsRequset;
import com.team2.insulatingtools.modular.tools.pojo.request.ToolsRequest;
import com.team2.insulatingtools.modular.tools.pojo.response.RecordStatisticsImportResultsExcel;
import com.team2.insulatingtools.modular.tools.pojo.response.RecordStatisticsResponse;
import com.team2.insulatingtools.modular.tools.service.RecordStatisticsService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * .           ,%%%%%%%%,
 * .         ,%%/\%%%%/\%%
 * .        ,%%%\c "" J/%%%
 * %.       %%%%/ o  o \%%%
 * `%%.     %%%%    _  |%%%
 * `%%      `%%%%(__Y__)%%'
 * //        ;%%%%`\-/%%%'
 * ((        /  `%%%%%%%'
 * \\    .'          |
 * \\  /       \  | |
 * \\/         ) | |
 * \         /_ | |__
 * (___________)))))))
 * 攻城狮 永无bug!
 *
 * @ClassName RecordStatisticsController
 * @Author lemon
 * @create 2023/4/6 15:09
 */
@RestController
@ApiResource(name = "记录统计")
public class RecordStatisticsController {
    @Resource
    private RecordStatisticsService service;


    @GetResource(name = "显示记录统计列表", path = ("/recordstatistics/show"))
    public ResponseData showRecordStatistics(RecordStatisticsRequset recordr) {
        return new SuccessResponseData(service.showRecordStatistics(recordr.getOrgName(), recordr.getToolName()));
    }

    @PostResource(name = "导出记录统计excel", path = "/recordstatistics/export")
    public void export(HttpServletResponse response, @RequestBody Map<String,List<RecordStatisticsResponse>> recordObject) {
        List<RecordStatisticsResponse> recordStatisticsList = recordObject.get("arr");
        service.exportExcel(response, recordStatisticsList);
    }

    @PostResource(name = "导入记录统计excel", path = "/recordstatistics/import")
    public void importExcel(MultipartFile file, HttpServletResponse response) throws IOException {
        service.importExcel(file, response);
    }
}
